package com.jbm.jbmsupplier.activity.loadhomepage.presenter

import android.content.Context
import android.view.View
import com.jbm.enterapplication.InterfaceMaArr
import com.jbm.jbmsupplier.activity.loadhomepage.mode.ListFrement_Mode
import com.jbm.jbmsupplier.activity.loadhomepage.orderadapter.ManageAdapterOrder
import com.jbm.jbmsupplier.activity.loadhomepage.view.ListFrement_View_Con
import com.jbm.jbmsupplier.view.DialogLoading
import com.jbm.jbmsupplier.view.DoubleButtonDialog
import com.jbm.onehome.iface.IorderEntity
import java.util.*

/**
 * Created by 家帮忙 on 2017/8/23.
 */
class ListFrement_Prement_Con :ListFrement_Prement_Infa{
    override fun LoadDateguidang(tag: Int) {//更新管理端归档订单
        lsitfrement_mode.LoadDateguidang(tag,listfrementviewcon!!.getStatic(),object :InterfaceMaArr<String, IorderEntity>{
            override fun setError(err: String, boolean: Boolean) {
                setDialogding()
                if ( listfrementviewcon?.getPulltorefre() != null) {
                    listfrementviewcon?.getPulltorefre()!!.onRefreshComplete()
                }
                if(boolean==false){
                    hint(err)
                }

            }

            override fun onSuccess(t: String, boolean: Boolean, arraylist: ArrayList<IorderEntity>) {
                setDialogding()
                if ( listfrementviewcon?.getPulltorefre() != null) {
                    listfrementviewcon?.getPulltorefre()!!.onRefreshComplete()
                }
                when(t){
                    "0" ->{//没有任何数据
                        if (boolean==true){
                            manageadapter= ManageAdapterOrder(context,arraylist)
                            listfrementviewcon?.getPulltorefre()?.setAdapter(manageadapter)
                        }else if (boolean==false){
//                            manageadapter?.notifyDataSetChanged()
                        }

                    }
                    "1" ->{//第一次初始化
                        if (manageadapter==null){
                            manageadapter= ManageAdapterOrder(context,arraylist)
                            listfrementviewcon?.getPulltorefre()?.setAdapter(manageadapter)
                        }else{
                            listfrementviewcon?.getPulltorefre()?.setAdapter(manageadapter)
                            manageadapter?.notifyDataSetChanged()
                        }
                    }
                    "2" ->{//更新数据
                        if (manageadapter==null){
                            manageadapter= ManageAdapterOrder(context,arraylist)
                            listfrementviewcon?.getPulltorefre()?.setAdapter(manageadapter)
                        }else{
                            manageadapter?.getDataNotify(arraylist)
                        }
                    }

                }



            }


        })
    }

    override fun LoadDateJBM(tag: Int) {//更新家帮忙订单
       lsitfrement_mode.LoadDateJBM(tag,listfrementviewcon!!.getStatic(),object :InterfaceMaArr<String,IorderEntity>{
           override fun setError(err: String, boolean: Boolean) {
               setDialogding()
               if ( listfrementviewcon?.getPulltorefre() != null) {
                   listfrementviewcon?.getPulltorefre()!!.onRefreshComplete()
               }
               if(boolean==false){
                   hint(err)
               }

           }

           override fun onSuccess(t: String, boolean: Boolean, arraylist: ArrayList<IorderEntity>) {
               setDialogding()
               if ( listfrementviewcon?.getPulltorefre() != null) {
                   listfrementviewcon?.getPulltorefre()!!.onRefreshComplete()
               }
               when(t){
                   "0" ->{//没有任何数据
                       if (boolean==true){
                           manageadapter= ManageAdapterOrder(context,arraylist)
                           listfrementviewcon?.getPulltorefre()?.setAdapter(manageadapter)
                       }else if (boolean==false){
//                           manageadapter?.notifyDataSetChanged()
                       }

                   }
                   "1" ->{//第一次初始化
                       if (manageadapter==null){
                           manageadapter= ManageAdapterOrder(context,arraylist)
                           listfrementviewcon?.getPulltorefre()?.setAdapter(manageadapter)
                       }else{
                           listfrementviewcon?.getPulltorefre()?.setAdapter(manageadapter)
                           manageadapter?.notifyDataSetChanged()
                       }
                   }
                   "2" ->{//更新数据
                       if (manageadapter==null){
                           manageadapter= ManageAdapterOrder(context,arraylist)
                           listfrementviewcon?.getPulltorefre()?.setAdapter(manageadapter)
                       }else{
                           manageadapter?.getDataNotify(arraylist)
                       }
                   }

               }



           }


       })
    }

    var lsitfrement_mode= ListFrement_Mode();
  var listfrementviewcon :ListFrement_View_Con?=null
    var context:Context?=null
    constructor(listfrementviewcon: ListFrement_View_Con?, context:Context?) {
        this.listfrementviewcon = listfrementviewcon
        this.context=context
        dialogLoading = DialogLoading(context!!, "加载中.....", true)
    }


    override fun LoadDateConstrucation() {//初始化第一次数据
//        if (listfrementviewcon!!.getBoolean()==null|| listfrementviewcon!!.getCount()===0){
//            lsitfrement_mode.LoadDateConstru(object :ListRement_Mode_Inte.OnClicklinner{
//                override fun setSuccess() {
//
//                }
//                override fun setError() {
//
//                }
//            })
//        }
//
//
    }
    var  dialogLoading: DialogLoading?=null
    var manageadapter:ManageAdapterOrder?=null
    override fun LoadDateConstrcations(tag:Int) {//更新管理端待分配
        dialogLoading?.show()
        lsitfrement_mode.LoadDateConstrus(tag,listfrementviewcon!!.getStatic(),object :InterfaceMaArr<String, IorderEntity>{
            override fun setError(err: String, boolean: Boolean) {
                setDialogding()
                if ( listfrementviewcon?.getPulltorefre() != null) {
                    listfrementviewcon?.getPulltorefre()!!.onRefreshComplete()
                }
                if(boolean==false){
                    hint(err)
                }

            }

            override fun onSuccess(t: String, boolean: Boolean, arraylist: ArrayList<IorderEntity>) {
                setDialogding()
                if ( listfrementviewcon?.getPulltorefre() != null) {
                    listfrementviewcon?.getPulltorefre()!!.onRefreshComplete()
                }
                when(t){
                    "0" ->{//没有任何数据
                        if (boolean==true){
                            manageadapter= ManageAdapterOrder(context,arraylist)
                            listfrementviewcon?.getPulltorefre()?.setAdapter(manageadapter)
                        }else if (boolean==false){
//                            manageadapter?.notifyDataSetChanged()
                        }

                    }
                    "1" ->{//第一次初始化
                        if (manageadapter==null){
                            manageadapter= ManageAdapterOrder(context,arraylist)
                            listfrementviewcon?.getPulltorefre()?.setAdapter(manageadapter)
                        }else{
                            listfrementviewcon?.getPulltorefre()?.setAdapter(manageadapter)
                            manageadapter?.notifyDataSetChanged()
                        }
                    }
                    "2" ->{//更新数据
                        if (manageadapter==null){
                            manageadapter= ManageAdapterOrder(context,arraylist)
                            listfrementviewcon?.getPulltorefre()?.setAdapter(manageadapter)
                        }else{
                            manageadapter?.getDataNotify(arraylist)
                        }
                    }

                }



            }


        })

    }
    //一些提示的时候调用
    fun hint(name: String) {
        val dialog = DoubleButtonDialog(context, name)
        dialog.getokbtn().setOnClickListener(View.OnClickListener { dialog.dismiss() })
        dialog.setisVisibility()

    }
    fun setDialogding() {
        if (dialogLoading != null) {
            dialogLoading!!.dismiss()
        }
    }
}